package com.atguigu.ext;

import com.atguigu.bean.Red;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @Description :
 * @Version : V1.0.0
 * @Date : 2022/9/18 10:11
 */
@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor, ApplicationContextAware {
    private ApplicationContext applicationContext;
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("MyBeanFactoryPostProcessor...");
        System.out.println("bean define count:" + beanFactory.getBeanDefinitionCount());
        System.out.println("bean name:" + Arrays.asList(beanFactory.getBeanDefinitionNames()));
    }


    public void say() {
        System.out.println("i am MyBeanFactoryPostProcessor");
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("set application context");
        this.applicationContext = applicationContext;
    }
}
